// pages/chartere_bus6/choose_hotel6-10/choose_hotel6-10.js
var httpUtil = require('../../utils/httpUtil.js');
var util = require('../../utils/util.js');

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    airport:{},
    wineshopList:{},
    list:[],
    text:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var pages = getCurrentPages();

    var prevPage = pages[pages.length - 2]; //上一个页面
    var id=prevPage.data.airport.id;
    that.getWineshopList(id);
   },
  getWineshopList:function(id){
    var that = this;
    httpUtil.getHttp("/country/list/winesho", {id:id}, function (res) {
      that.setData({
        wineshopList: res,
        list:res
      })
    })
  },
  setText: function (e) {
    var that = this;
    var value = e.detail.value;
    var list=[];
    var wineshopList = that.data.wineshopList;
    if (wineshopList != null && wineshopList.length>0){
      for (var i = 0; i < wineshopList.length;i++){
        if(wineshopList[i].name.indexOf!=-1){
          list.push(wineshopList[i]);
        }
      } 
    }
    that.setData({
      list:list,
      text:value
    })
  }, addWineshop: function (e){
    var that=this;
    var index = e.target.dataset.id;
    console.log(index);
    console.log(that.data.list);
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面

    prevPage.setData({
      wineshop: that.data.list[index]
    })
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})